-
Notifications
You must be signed in to change notification settings - Fork 148
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CMake Improvements #615
CMake Improvements #615
Conversation
Previously, builds would fail with a message stating that there's no such command "true". CMAKE_C[XX]_ARCHIVE_FINISH is not a boolean option, but instead should be a string for how to run ranlib. This simply sets that to the default, but it could instead be removed in the future now that GCC binutils has lto automatically loading.
This removes the arguments that LLD cannot receive from the base default_build file, and moves them to the GCC-specific toolchain setup. This reformats all linker arguments to allow for CMake to auto-format them depending on the toolchain (clang uses -Xlinker instead of -Wl).
constexpr cannot take the result of a cast that is equivalent to a reinterpret_cast, as defined by the C++ standard. GCC may allow it, but it's technically illegal and clang errors.
Naked is not allowed for functions that contain bodies other than asm functions. Per the GCC docs: "The only statements that can be safely included in naked functions are asm statements that do not have operands. All other statements, including declarations of local variables, if statements, and so forth, should be avoided." GCC silently allows this, but Clang notes this as a hard failure. Instead, the Default_Handler is marked as a generic interrupt, and the Reset_Handler is unmarked due to acting as the executable entrypoint.
This allows for configure-time selection of the linker script used by CMake, either at the command like with -DDAISY_STORAGE=qspi or in libraries that use libDaisy (by defining DAISY_STORAGE before inclusion).
Squashes 7+ warnings of this due to inclusion by other files.
This separates the massive root CMakeLists.txt file into libraries and places the respective configuration files closer to their source.
This ensures that we have architecture-specific configurations in a dedicated file while the LLVM and GNU toolchain files deal with their respective compilers only
config_ is never nullptr as it is initialized with the instantiation of a SaiHandle::Impl This allows -Werror to work on GCC.
Yeah considering how heavily it's used in certain places of libDaisy, and even shown in the examples, I think that's a reasonable solution. Ideally we could convert them to a static |
@beserge @stephenhensley any ideas when/how this might get merged? Are there any edits that need to happen for it to be done? |
Checked out and built, everything appears as it should be. I'll defer to @stephenhensley on the merge timing, but looks good to go on my end! One thing to note, I had to update my CMake install, my out of date version was giving me some trouble, but once that was done it was smooth sailing. |
Any update on a merge timeline for this? This would be a very welcome addition! |
Had to do manual merge resolution, since usbh_midi.c was already listed in the new refactored CMakeLists.txt. However, there also seems to be some issues with building on LLVM (on the CI side) now, so I'm going to poke about at that to see what's wrong. |
Alright, everything's working as it should now. Had to remove support for older versions of the LLVM Embedded Toolchain for ARM due to major breaking changes where the ARMv7E-M and ARMv7-M runtime libraries were merged, but considering we're only merging this now and 19.1.1 is the most current as of this comment, I think that's an acceptable solution. |
@stellar-aria Sounds good! I've been doing a little review/testing on this this week; I'll re-sync everything locally, and continue to test a bit more. So far, so good. Since it's getting a bit late today, and I'd like to test converting a few projects with the latest version, I'll probably end up merging this on Monday unless any issues arise. |
So I am running into one issue that I didn't realize initially. On Mac OS, I've built with ARM GCC 10.3-2021.10 (10.3.1 20210824 release) In both cases, programs built seem to run properly after being programmed to the Daisy. I've used the CMakeLists.txt: cmake_minimum_required(VERSION 3.26)
cmake_policy(SET CMP0048 NEW)
include(FetchContent)
FetchContent_Declare(daisy
GIT_REPOSITORY https://github.com/stellar-aria/libDaisy
GIT_TAG 5086cc0
)
FetchContent_MakeAvailable(daisy)
project(daisyblink VERSION 0.0.1)
set(FIRMWARE_NAME daisyblink)
set(FIRMWARE_SOURCES
${CMAKE_CURRENT_LIST_DIR}/Blink/main.cpp
)
set(DAISY_GENERATE_BIN ON)
include(DaisyProject)
target_include_directories(${FIRMWARE_NAME} PRIVATE include) main.cpp #include "daisy_seed.h"
using namespace daisy;
DaisySeed hardware;
int main()
{
hardware.Init();
while (true)
{
hardware.SetLed(true);
hardware.DelayMs(500);
hardware.SetLed(false);
hardware.DelayMs(500);
}
} Built with the following:
I vaguely recall running into this a long time ago (possibly an issue with LTO, or something), but it was several years ago. I'll retry with different optimization, etc. and see if I can narrow down the issue, but it's also possible I'm just overlooking something obvious. |
@stephenhensley I've used your test case and it compiles and works (uploaded via the Daisy web programmer) with GCC 13.2.1 (see attached files) even after a cold-boot and power cycle, so next I'm going to try with 10-2020-q4. |
I can confirm the behavior on 10-2020-q4, I'm going to check versions upwards to see where it resolves |
Issue is present in 11.3.1 and resolved in 12.2.1 |
@stellar-aria thanks for stepping through that, and finding where it improved! -- I'll continue testing with a newer compiler. Aside from this issue everything seems great so far. Last things I want to check are bootloader/linker script related, but I don't anticipate any issues. |
TLDR: Remove ARM GCC will usually optimize this loop to builtin memset but CMake build has In my test with real HW removing |
Thank you so much for figuring that out @asavartsov. It looks like that was added in one of the first few refactor commits I was doing, probably pulled from somewhere else originally, and it's been so long I have no idea what prompted it being there or what I was thinking 😅 It looks like without it, there's now some size changes in some of the binaries for clang, which is preventing them from fully building, so some of the examples might have to be prodded to work properly or removed from the test build |
Very strange indeed. Good catch. @asavartsov thanks for digging in, and clarifying what was going on a bit more! I think for the time being, we can except any of the currently included examples that are too large in order to get an initial version of this merged/passing CI again. Another, slightly more medium-term, solution would be to build those examples with the bootloader (minding that at least the SDMMC example would require a custom linker so the FIL objects, etc. can be in AXI SRAM). However, I think coverage for all examples w/ CMake can be a goal we work toward rather than requiring it as a part of this PR. I haven't personally run into any further issues yet, but I haven't had a ton more time for further testing. This also doesn't really have much effect on the (current) primary Make-based build system that seems unaffected by any of the llvm/cmake build issues we've discussed in the last few days. Let me know what you think, and we can go from there. |
@stephenhensley Yeah, I'm in agreement. Investigation on my end has indicated that this behavior is actually Clang/LLVM more strictly conforming to the C++ standard than GCC does, which moves this from a codebase error to something more complicated. I might poke some LLVM devs and ask if they have any suggestions for how to go about achieving the behavior we want (large array-like globals in .bss). In the meantime, I've reduced the Clang CI's build tasks from all of the examples down to just BootloaderBlink, which should at least verify that the CI works, even if not for all of our general GCC test cases. Meanwhile the GCC stuff is all up to date with the current collection of examples. I'd say this is probably good to merge at this point, as long as you find no other issues. Bringing up conformance between the two compilers can definitely be another PR, if at all. |
In this particular case one could (and probably should) put MIDII/FIFO objects (which will take buffers with them) in any other section of their choice outside of FLASH region manually. Or avoid globals and trust compiler but it would be a bit trickier if you need to interact with audio callback since you can’t pass anything (I would imagine at least some opaque pointer) to it. So means to override this more or less exist for end user. |
Alright! I'm signing off. Thanks again, @stellar-aria for the tremendous PR! And sorry for how long it took to get it merged. |
Over the past year I've done some work on improving the state of the CMake build system, initially inspired by fixing building on native Windows, and then expanding in scope.
This is part 1 of the work towards fully migrating to CMake as per #606.
Changes in this PR include:
examples
(these are not part of the defaultall
target)TOOLCHAIN_PREFIX
to the CMake standardCMAKE_C_COMPILER
for manually selecting a toolchainExample project: